package com.hirsi.common.module.auth.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.common.core.annotation.IgnoreAccessTokenValid;
import com.hirsi.common.core.annotation.RequestBodyParam;
import com.hirsi.common.module.auth.service.AuthService;
import com.hirsi.common.module.auth.vo.param.AccountLoginParam;
import com.hirsi.common.module.auth.vo.param.PhoneLoginParam;
import com.hirsi.common.module.auth.vo.param.SendSmsCodeParam;
import com.hirsi.common.module.auth.vo.result.CaptchaResult;
import com.hirsi.common.module.auth.vo.result.TokenResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "授权登录相关接口")
@ApiSupport(order = 1)
@RestController
@RequestMapping("rest/v1/auth")
public class AuthController {

    @Autowired
    private AuthService authService;


    @IgnoreAccessTokenValid
    @ApiOperation("获取Base64图片验证码")
    @ApiOperationSupport(order = 10)
    @GetMapping("captcha")
    public CaptchaResult captcha() {
        return authService.captcha();
    }

    @IgnoreAccessTokenValid
    @ApiOperation("账号密码登录")
    @ApiOperationSupport(order = 11)
    @PostMapping("account_login")
    public TokenResult accountLogin(@RequestBodyParam @Validated AccountLoginParam param) {
        return authService.accountLogin(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation("发送短信验证码")
    @ApiOperationSupport(order = 12)
    @PostMapping("send_sms_code")
    public void sendSmsCode(@RequestBodyParam @Validated SendSmsCodeParam param) {
        authService.sendSmsCode(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation("手机验证码登录")
    @ApiOperationSupport(order = 13)
    @PostMapping("phone_login")
    public TokenResult phoneLogin(@RequestBodyParam @Validated PhoneLoginParam param) {
        return authService.phoneLogin(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation("退出登录")
    @ApiOperationSupport(order = 14)
    @PostMapping("logout")
    public void logout() {
        authService.logout();
    }
}
